package com.acme.domain.email.impl;

import com.acme.domain.email.Email;
import com.acme.domain.email.Queue;

import java.util.LinkedList;
import java.util.List;

public class QueueImpl implements Queue {

    private boolean queueClosed = false;
    List<Email> mails = new LinkedList<Email>();

    public synchronized void addEmail(Email email) {
        if (!(isQueueClosed())) {
            mails.add(email);
            this.notifyAll();
        }

    }

    public boolean isQueueClosed() {
        return queueClosed;
    }

    public void setQueueClosed(boolean queueClosed) {
        this.queueClosed = queueClosed;
    }

    public synchronized Email getEmail(int index) {
        return mails.remove(index);
    }

    public boolean isEmpty() {
        return mails.isEmpty();
    }
}
